﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Model;
using University.Workshop.Presenters.AppointmentFolder;
namespace University.Workshop.WinApp
{
    public partial class SearchAppointmentToUpdate : Form, ISearchAppointment
    {
        private ICollection<Appointment> appointments;
        private PresenterSearchAppointment presenter;
        private Appointment father;
        int index;
        public SearchAppointmentToUpdate()
        {
            InitializeComponent();
            appointments = new List<Appointment>();
            presenter = new PresenterSearchAppointment(this);
            index = -1;
        }

        public SearchAppointmentToUpdate(Appointment appointment)
        {
            InitializeComponent();
            appointments = new List<Appointment>();
            presenter = new PresenterSearchAppointment(this);
            father = appointment;
            index = -1;
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {
            appointments = presenter.SearchAppointment();
            dgwBuscar.DataSource = appointments;
        }

        private void SearchAppointmentToUpdate_Load(object sender, EventArgs e)
        {

        }

        public string PatientId
        {
            get
            {
                return txtPatientId.Text;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        private void btnSeleccionar_Click(object sender, EventArgs e)
        {
            if (index != -1)
            {
                father.AppointmentId = (int)dgwBuscar.CurrentRow.Cells["AppointmentId"].Value;
                father.PatientId = dgwBuscar.CurrentRow.Cells["PatientId"].Value.ToString();
                father.Specialty = dgwBuscar.CurrentRow.Cells["Specialty"].Value.ToString();
                father.DoctorId = dgwBuscar.CurrentRow.Cells["DoctorId"].Value.ToString();
                father.Date = dgwBuscar.CurrentRow.Cells["Date"].Value.ToString();
                father.Time = dgwBuscar.CurrentRow.Cells["Time"].Value.ToString();
                father.Description = dgwBuscar.CurrentRow.Cells["Description"].Value.ToString();
                father.Observations = dgwBuscar.CurrentRow.Cells["Observations"].Value.ToString();
                this.Dispose();
            }
            else
                MessageBox.Show("Seleccione una cita");
            
        }

        private void dgwBuscar_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void dgwBuscar_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            index = e.RowIndex;
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
